package com.tsinghuabigdata.edu.ddmath.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;


import com.tsinghuabigdata.edu.ddmath.R;

import java.util.List;

/**
 * Created by Administrator on 2016/12/13.
 */

public class FiltrateAdapter extends BaseAdapter {

    private int seclectPosition;
    private Context mContext;
    private List<String> mDatas;

    public FiltrateAdapter(Context context, List<String> list, int position) {
        mDatas = list;
        mContext = context;
        seclectPosition = position;
//        filtrateHandle = (FiltrateHandle) context;
    }

    public void setSelectPostion( int position ){
        seclectPosition = position;
    }

    @Override
    public int getCount() {
        if (mDatas != null) {
            return mDatas.size();
        }
        return 0;
    }

    @Override
    public Object getItem(int position) {
        if (mDatas != null) {
            return mDatas.get(position);
        }
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;

        if (convertView == null) {
            // 没有复用
            convertView = View.inflate(mContext, R.layout.item_filtrate,
                    null);
            holder = new ViewHolder();
            convertView.setTag(holder);
            // 给holder找view
            holder.tvName = (TextView) convertView
                    .findViewById(R.id.tv_name);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        String data = mDatas.get(position);
        // 给holder中的view设置数据
        holder.tvName.setText(data);
        if (this.seclectPosition == position){
            holder.tvName.setTextColor(mContext.getResources().getColor(R.color.dd_9577EC));
        }else {
            holder.tvName.setTextColor(mContext.getResources().getColor(R.color.dd_999999));
        }
        return convertView;
    }

    class ViewHolder {
        TextView tvName;
    }
}
